#include <iostream>
#include <cstdlib>
#include <string>  //链表中不能存储带有string类的数据类型
using namespace std;
typedef struct studentLinkedList{ //定义名为studentLinkedList的结构体
    char name[20];
	int age;
	int number;
	struct studentLinkedList *next; //定义名为studentLinkedList的next指针
} *StudLinkedList ;  //定义名为studentLinkedList类型的指针变量

StudLinkedList CreatTheLinkedList(){
	StudLinkedList head; //定义头指针
	if(head=(StudLinkedList)malloc(sizeof(studentLinkedList))){ //为头指针申请空间
		printf("Creat the Head Success! \n"); //申请成功输出"Creat the Head Success!"
		return head; //并且返回头指针
	}else{
		return NULL; //如果申请失败返回NULL
	}
}

StudLinkedList CreatListStu(StudLinkedList head){ //定义函数，创建链表，尾插法
	StudLinkedList stu,r; //定义局部变量stu,r
	string select; 
	head->next=NULL; //设置头指针的next为空
	r=head; //给中间变量指针赋值为head
	do{
		stu=(StudLinkedList)malloc(sizeof(studentLinkedList)); //stu变量申请空间
		cout<<"Please input the student's name: ";
		cin>>stu->name;
		cout<<"Please input the student's age: ";
		cin>>stu->age;
		cout<<"Please input the student's number: ";
		cin>>stu->number;
		r->next=stu; //r的next的指向为刚刚输入的值
		r=stu; //r赋值成stu的值
		cout<<"Y/N?\n";
		cin>>select;
	}while(select=="Y"||select=="y");
	r->next=NULL; //r的next的指向为空
	return head; //返回头指针
}

StudLinkedList CreatListStu(StudLinkedList head,int n){ //函数重载，同样创建链表
	StudLinkedList stu,r;
	head->next=NULL;
	r=head;
	while(stu->age!=0){
		stu=(StudLinkedList)malloc(sizeof(studentLinkedList));
		cout<<"Please input the student's name: ";
		cin>>stu->name;
		cout<<"Please input the student's age: ";
		cin>>stu->age;
		cout<<"Please input the student's number: ";
		cin>>stu->number;
		r->next=stu;
		r=stu;
	}
	r->next=NULL;
	return head;
}

int main(){
	CreatListStu(CreatTheLinkedList());
	CreatListStu(CreatTheLinkedList(),1);
	return 0;
}